<template>
  <!-- Stagewise 工具栏 - 仅在开发模式下显示 -->
  <StagewiseToolbar v-if="isDev" :config="stagewiseConfig" />
  
  <el-container class="layout-container">
    <!-- 侧边栏导航 -->
    <el-aside width="240px" class="aside-container">
      <div class="logo-container">
        <div class="logo-placeholder">
          <span class="logo-text">AI</span>
        </div>
        <h1 class="system-title">AI教学系统</h1>
      </div>
      
      <el-menu
        :default-active="activeMenu"
        class="el-menu-vertical"
        @select="handleSelect"
        router
      >
        <el-menu-item index="/" class="menu-item">
          <el-icon><house /></el-icon>
          <span>首页</span>
        </el-menu-item>
        <el-menu-item index="/create_video" class="menu-item">
          <el-icon><video-camera /></el-icon>
          <span>PPT生成视频</span>
        </el-menu-item>
        <el-menu-item index="/create-ppt" class="menu-item">
          <el-icon><document /></el-icon>
          <span>PPT生成</span>
        </el-menu-item>
        <el-menu-item index="/question-generator" class="menu-item">
          <el-icon><question-filled /></el-icon>
          <span>智能出题</span>
        </el-menu-item>
        <el-menu-item index="/videos" class="menu-item">
          <el-icon><video-play /></el-icon>
          <span>视频列表</span>
        </el-menu-item>
      </el-menu>
      
      <div class="app-version">v1.2.0</div>
    </el-aside>
    
    <!-- 主内容区 -->
    <el-container class="main-container">
      <!-- 顶部导航栏 -->
      <el-header class="header-container">
        <div class="header-content">
          <div class="header-left">
            <el-breadcrumb separator="/">
              <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
              <el-breadcrumb-item>{{ currentRoute }}</el-breadcrumb-item>
            </el-breadcrumb>
          </div>
          
          <div class="header-right">
            <div class="action-buttons">
              <el-button type="text" icon="bell" class="notification-btn" />
              <el-button type="text" icon="setting" class="settings-btn" />
            </div>
            
            <el-dropdown>
              <span class="user-profile">
                <el-avatar :size="36" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
                <div class="user-info">
                  <span class="username">管理员</span>
                  <span class="user-role">系统管理员</span>
                </div>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item>
                    <el-icon><user /></el-icon>个人信息
                  </el-dropdown-item>
                  <el-dropdown-item>
                    <el-icon><setting /></el-icon>系统设置
                  </el-dropdown-item>
                  <el-dropdown-item divided>
                    <el-icon><switch-button /></el-icon>退出登录
                  </el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </div>
      </el-header>
      
      <!-- 页面内容 -->
      <el-main class="main-content">
        <router-view v-slot="{ Component }">
          <transition name="fade" mode="out-in">
            <div class="page-container">
              <component :is="Component" />
            </div>
          </transition>
        </router-view>
      </el-main>
      
      <!-- 页脚 -->
      <el-footer class="footer-container">
        <div class="footer-content">
          <div class="footer-links">
            <a href="#">关于我们</a>
            <a href="#">帮助中心</a>
            <a href="#">服务条款</a>
            <a href="#">隐私政策</a>
          </div>
          <div class="copyright">
            © 2025 AI教学系统 - 让教育更智能
          </div>
        </div>
      </el-footer>
    </el-container>
  </el-container>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { 
  House, 
  VideoCamera, 
  VideoPlay, 
  Document, 
  QuestionFilled,
  User,
  Setting,
  SwitchButton
} from '@element-plus/icons-vue'

// Stagewise 工具栏导入
import { StagewiseToolbar } from '@stagewise/toolbar-vue'
import { VuePlugin } from '@stagewise-plugins/vue'

// 开发模式检测
const isDev = process.env.NODE_ENV === 'development'

// Stagewise 配置
const stagewiseConfig = {
  plugins: [VuePlugin]
}

const router = useRouter()
const route = useRoute()

const activeMenu = computed(() => route.path)
const currentRoute = computed(() => {
  const routeMap: Record<string, string> = {
    '/': '首页',
    '/create_video': 'PPT转视频',
    '/create-ppt': 'PPT生成',
    '/question-generator': '智能出题',
    '/videos': '视频列表'
  }
  return routeMap[route.path] || '未知页面'
})

const handleSelect = (key: string) => {
  router.push(key)
}
</script>

<style scoped>
.layout-container {
  height: 100vh;
  display: flex;
  background-color: var(--bg-body);
}

/* 侧边栏样式 */
.aside-container {
  background: linear-gradient(145deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  z-index: 10;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.aside-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(45deg, rgba(255,255,255,0.1) 0%, transparent 50%, rgba(255,255,255,0.05) 100%);
  pointer-events: none;
}

.logo-container {
  padding: var(--space-xl) var(--space-lg);
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  position: relative;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
  margin: var(--space-sm);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.logo-placeholder {
  width: 50px;
  height: 50px;
  background: linear-gradient(135deg, #ff6b6b, #feca57);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: var(--space-md);
  box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
  position: relative;
  overflow: hidden;
}

.logo-placeholder::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(45deg, transparent, rgba(255,255,255,0.3), transparent);
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%) translateY(-100%) rotate(45deg); }
  100% { transform: translateX(100%) translateY(100%) rotate(45deg); }
}

.logo-text {
  font-size: 22px;
  font-weight: 800;
  background: linear-gradient(45deg, #fff, #f1f2f6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 2px 4px rgba(0,0,0,0.2);
  position: relative;
  z-index: 1;
}

.system-title {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, #fff 0%, #e8eaf2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 2px 8px rgba(0,0,0,0.15);
  letter-spacing: 0.5px;
}

.el-menu {
  border-right: none;
  background: transparent;
  flex: 1;
  padding: var(--space-md);
}

.menu-item {
  margin: var(--space-sm) 0;
  border-radius: var(--radius-md);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(5px);
}

.menu-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: all 0.5s;
}

.menu-item:hover::before {
  left: 100%;
}

.menu-item:hover {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0.05)) !important;
  transform: translateX(8px) scale(1.02);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.menu-item.is-active {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.25), rgba(255, 255, 255, 0.1)) !important;
  box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
  transform: translateX(5px);
  border-left: 4px solid rgba(255, 255, 255, 0.8);
}

.menu-item .el-icon {
  font-size: 18px;
  margin-right: var(--space-sm);
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.menu-item span {
  font-weight: 500;
  font-size: 15px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.1);
  letter-spacing: 0.3px;
  color: #ffffff !important;
}

.menu-item {
  color: #ffffff !important;
}

.app-version {
  padding: var(--space-md);
  text-align: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.1);
  font-weight: 500;
  letter-spacing: 1px;
  backdrop-filter: blur(5px);
}

/* 顶部导航栏样式 */
.header-container {
  background-color: var(--bg-card);
  box-shadow: var(--shadow-sm);
  padding: 0 var(--space-lg);
  height: 64px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  z-index: 5;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.action-buttons {
  display: flex;
  gap: var(--space-xs);
}

.notification-btn, .settings-btn {
  font-size: 18px;
  color: var(--text-secondary);
  transition: var(--transition);
}

.notification-btn:hover, .settings-btn:hover {
  color: var(--primary);
  transform: scale(1.1);
}

.user-profile {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.user-profile:hover {
  background-color: var(--gray-200);
}

.user-info {
  display: flex;
  flex-direction: column;
  margin-left: var(--space-sm);
}

.username {
  font-weight: 500;
  color: var(--text-primary);
}

.user-role {
  font-size: 12px;
  color: var(--gray-600);
}

/* 主内容区样式 */
.main-content {
  padding: var(--space-lg);
  background-color: var(--bg-body);
  min-height: calc(100vh - 64px - 48px); /* 减去header和footer高度 */
}

.page-container {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-lg);
  min-height: calc(100vh - 180px); /* 调整高度 */
}

/* 页脚样式 */
.footer-container {
  height: 48px;
  background-color: var(--bg-card);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
}

.footer-content {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 var(--space-lg);
}

.footer-links {
  display: flex;
  gap: var(--space-lg);
}

.footer-links a {
  color: var(--text-secondary);
  font-size: 14px;
  transition: var(--transition);
}

.footer-links a:hover {
  color: var(--primary);
}

.copyright {
  color: var(--gray-600);
  font-size: 14px;
}

/* 过渡动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

/* 响应式设计 */
@media screen and (max-width: 768px) {
  .aside-container {
    width: 64px !important;
  }
  
  .system-title, .app-version, .el-menu-item span {
    display: none;
  }
  
  .logo-placeholder {
    margin-right: 0;
  }
  
  .user-info {
    display: none;
  }
  
  .footer-content {
    flex-direction: column;
    gap: var(--space-sm);
    text-align: center;
  }
}
</style>
